package com.platform.wechat.service.impl;

import com.platform.wechat.common.JsonBean;
import com.platform.wechat.entity.Platform;
import com.platform.wechat.mapper.PlatformMapper;
import com.platform.wechat.service.PlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 嗷嗷嗷
 * @title: PlatformServiceImpl
 * @projectName wechat114
 * @description: TODO
 * @date 2021/7/2819:57
 */
@Service
public class PlatformServiceImpl implements PlatformService {
    @Autowired
    private PlatformMapper platformMapper;


    /**
     * 登陆
     * @param platformPhone
     * @return
     */
    @Override
    public JsonBean selest(String platformPhone) {
        JsonBean jsonBean = new JsonBean(-1,"ok",null);
        int i = platformMapper.selectPrismarys(platformPhone);
        if (i ==0){
            Platform platform = new Platform();
            platform.setPlatformPhone(platformPhone);
            int i1 = platformMapper.insertSelective(platform);
            if ((i1>0)){
                jsonBean.setCode(0);
                jsonBean.setMsg("ok");
            }
        }
        return jsonBean;
    }

    /**
     * 实名认证
     * @param platform
     * @return
     */
    @Override
    public JsonBean insert(Platform platform) {
        int i=0;
        JsonBean jsonBean = new JsonBean(-1,"ok",null);
        String platformPhone = platform.getPlatformPhone();
            int delete = platformMapper.delete(platformPhone);
            i = platformMapper.insertSelective(platform);
            Platform platform1 = platformMapper.selectPrismaryBys(platformPhone);
        if (i>0){
            jsonBean.setCode(0);
            jsonBean.setMsg("成功");
            jsonBean.setData(platform1);
        }
        return jsonBean;
    }

    /**
     * 修改手机号
     * @param platform
     * @return
     */
    @Override
    public JsonBean update(Platform platform,String phone) {
        JsonBean jsonBean = new JsonBean(-1,"ok",null);
        Platform platform1 = platformMapper.selectPrismaryBys(phone);
        platform.setPlatformId(platform1.getPlatformId());
        int i = platformMapper.updateByPrimaryKeySelective(platform);
        if (i>0){
            jsonBean.setCode(0);
            jsonBean.setMsg("修改成功");
        }
        return jsonBean;
    }

    /**
     * 实名认证状态
     * @param platformPhone
     * @return
     */
    @Override
    public JsonBean selects(String platformPhone) {
        JsonBean ok = new JsonBean(0, "ok", null);
        Platform platform = platformMapper.selectPrismaryBys(platformPhone);
        if (platform==null){
            ok.setCode(-1);
        }else  {
            if (platform.getPlatformName()==null){
                ok.setCode(-1);
            }
        }
        ok.setData(platform);

        return ok;
    }

}
